//
//  HJMainTabBar.swift
//  sinaWeibo
//
//  Created by hjun on 16/3/20.
//  Copyright © 2016年 hjun. All rights reserved.
//

import UIKit
let TabbarItemcount = 5
class HJMainTabBar: UITabBar {
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        let width = frame.width / CGFloat(TabbarItemcount)
        
        var index = 0
        
        for view in subviews{
            
            //            let cls = NSClassFromString("UITabBarButton")
        
  if view.isKindOfClass((NSClassFromString("UITabBarButton"))!){
                view.frame = CGRect(x: CGFloat(index) * width, y: 0, width: width, height: frame.height)
                
                
                index += index == 1 ? 2 : 1
                
                //                index++
                //
                //                if index == 2{
                //                    index++
                //                }
            }
        }
        
        composeBtn.frame = CGRect(x: 2 * width, y: 0, width: width, height: frame.height)
    }
    
    
    //MARK: 懒加载
    
    private lazy var composeBtn : UIButton = {
        
        let button = UIButton()
        
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(button)
        
        return button
    }()
    
    
    
}
